import axios from "axios"
export default {	
   data(){
    	return{
    		beizhu:'',
    		cartfoods:[],
    		totalprice:0,
    		tanchuang:false,
    	}
   },
    mounted(){ 
	   	axios.get('/api/yidiancaiping').then((res) => {	 
  			//console.log(res.data);
			this.cartfoods=res.data;
			console.log(this.cartfoods);
			this.numbers=0;
			this.totalprice=0;
			for (var i=0;i<this.cartfoods.length;i++){					
				var price=this.cartfoods[i].cpjg;
				var number=Number(this.cartfoods[i].ydfs);
				//console.log(i);
				//console.log(number);
				this.totalprice +=price*number;				
			}
		});	
  	},
  	 methods: {
  	 	subtract: function (cartfood){
	  		axios.get('/api/quxiaodiancai?cpid='+cartfood.id).then((res) => {
	  			this.cartfoods=res.data;
				//console.log(this.cartfoods);
				this.numbers=0;
				this.totalprice=0;
				for (var i=0;i<this.cartfoods.length;i++){					
					var price=this.cartfoods[i].cpjg;
					var number=Number(this.cartfoods[i].ydfs);
					console.log(i);
					console.log(number);
					this.totalprice +=price*number;
					this.numbers+=number;
				}		  			
	  		})		  				  		
		},
		add: function (cartfood){		  		
			axios.get('/api/diancai?cpid='+cartfood.id).then((r) => {	      		     			      			      
	      		axios.get('/api/yidiancaiping').then((res) => {	 		      			
					this.cartfoods=res.data;
					this.numbers=0;
					this.totalprice=0;
					for (var i=0;i<this.cartfoods.length;i++){					
						var price=this.cartfoods[i].cpjg;
						var number=Number(this.cartfoods[i].ydfs);
						console.log(i);
						console.log(number);
						this.totalprice +=price*number;
						this.numbers+=number;
					}
			    });	
		    });	
		},		
		jiesuan: function (){
			
			axios.get('querendingdan').then((res) => {
				console.log(res);
				this.tanchuang=true;				
			});
			
			 sessionStorage["jiesuanzt"]=1;
			 sessionStorage["zt"]=0;
			 console.log(sessionStorage["zt"]);
		},	
  	 }
}